<template>
  <div>
    <!-- form组件

     -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="请输入手机号"
        required
        :rules="[
          { required: true, message: '手机号不能为空!' },
          {
            pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
            message: '请输入正确的手机格式!'
          }
        ]"
      />
      <van-field
        v-model="password"
        type="text"
        name="password"
        label="验证码"
        required
        placeholder="请输入验证码"
        :rules="[{ required: true, message: '验证码不能为空' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    // 表单校验通过之后触发
    /*
      values:表单内部输入元素
        name:value组成的一个对象
    */
    onSubmit (values) {
      console.log('submit', values)
    }
  }
}
</script>

<style></style>
